import com.java.demo.model.User;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WHY
 * Date: 2023-07-29
 * Time: 17:49
 */
public class BeanLifeComponent implements BeanNameAware {
    @Autowired
    private User user;

    @Override
    public void setBeanName(String s) {
        System.out.println("执行了BeanMNameAware->"+s);//s就是通知的名字
    }
    //使用当前注解表示在这个类里面可以实现初始化方法,
    @PostConstruct
    public void doPostConstruct(){
        System.out.println("执行了PostConstruct");
        user.toString();
    }
    //使用xml形式也实现了初始化方法
        public void init(){
            System.out.println("执行了init方法");
        }

//销毁bean 1.使用xml形式
    public void destroy(){
        System.out.println("执行了destroy方法");
    }
    //2.使用注解销毁bean
    @PreDestroy
    public void doDestroy(){
        System.out.println("执行了PreDestroy");
    }
    public void sayhi(){
        System.out.println("执行sayhi");
    }

}
